package cn.cby.controller;

import cn.cby.bean.Person;
import cn.cby.bean.User;
import cn.cby.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
public class IndexController extends BaseController{


    @RequestMapping("/userlist")
    public String index(Model model) {
        List<User> users = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            User user = new User();
            user.setId(i);
            user.setName("jason:"+i);
            user.setAddress("厦门:"+i);
            users.add(user);
        }
        model.addAttribute("users",users);
        return "userlist";
    }

    @Autowired
    PersonService service;

    /**
     * 跳转到登陆页面
     *
     * @return
     */
    @GetMapping(value = {"/login"})
    public String loginPage() {
        //跳转到登录页 login.html
        Person p = service.getPersonInfo();
        logI(p.getLastName());
        return "login";
    }
}
